<template>
  <div>

    <el-container>
      <el-header style="background-color: gray">
        <img src="@/assets/logo.png" alt="" style="width: 40px; position: relative; top: 10px">
        <span style="font-size: 20px; margin-left: 20px; color: yellow">移民管理系统</span>
        <el-dropdown style="float: right; height: 60px; line-height: 60px">
          <span class="el-dropdown-link" style="color: red; font-size: 16px;">
              欢迎您，{{ user.name }}<i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item>
              <div  @click="editUser">修改个人信息</div>
            </el-dropdown-item>
            <el-dropdown-item>
              <div  @click="logout">退出登录</div>
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-header>
    </el-container>

    <el-container>
      <el-aside style="overflow: hidden; min-height: 100vh; background-color: black; width: 250px">
        <el-menu
            router
            :default-active="$route.path"
            class="el-menu-vertical-demo"
            @open="handleOpen"
            @close="handleClose"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b">
          <el-menu-item index="/">
            <i class="el-icon-menu"></i>
            <span slot="title">系统首页</span>
          </el-menu-item>
          <el-submenu index="2" v-if="user.role === 'ROLE_ADMIN'">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>用户管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="/admin">用户信息</el-menu-item>
            </el-menu-item-group>
          </el-submenu>

          <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>信息管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="/type">图书分类</el-menu-item>
              <el-menu-item index="/book">图书信息</el-menu-item>
              <el-menu-item index="/audit">请假审核</el-menu-item>
              <el-menu-item index="/hotel">酒店信息</el-menu-item>
              <el-menu-item index="/reserve">预定酒店</el-menu-item>
              <el-menu-item index="/log">操作日志</el-menu-item>
              <el-menu-item v-if="user.role === 'ROLE_ADMIN'" index="/notice">系统通知</el-menu-item>
            </el-menu-item-group>
          </el-submenu>

        </el-menu>
      </el-aside>
      <el-main>
        <router-view/>
      </el-main>
    </el-container>
  </div>
</template>



<script>
export default {
  name: 'Layout',
  data(){
    return {
      user: localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user')) : {},   //取出数据，转成json
    }
  },
  methods: {

    // 登出
    logout(){
      localStorage.removeItem('user'); //清理
      this.$router.push('/login')
    },

    // 修改个人资料
    editUser(){
      this.$message.warning('程序员正在努力开发中....');
    }
  }
}
</script>


<style>
.el-menu {
  border-right: none !important;
}
</style>
